package com.min.log


import javassist.ClassPool
import javassist.CtClass
import javassist.CtMethod

class ActivityInject {

    static void injectDir(File classFile, String path) {
        ClassPool pool = ClassPool.getDefault()
        //截取当前类的路径，+8为classes加.的长度,再取出后边的.class的6位
        def packagePath = classFile.absolutePath.substring(classFile.absolutePath.lastIndexOf("classes") + 8, classFile.absolutePath.length() - 6)
        def replacePath = packagePath.replaceAll("/", ".")
        CtClass operationClass  = pool.get(replacePath)
        for (CtClass interfaceClass : operationClass.getInterfaces()) {
            println(interfaceClass.name)
        }
        CtMethod method = operationClass.getDeclaredMethod("onCreate")
        operationClass.writeFile(path)
        operationClass.detach()
    }

    private void recordLog() {
        
    }

}